package com.example.androworld;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.res.XmlResourceParser;

public class PowerCard {
	
	String classe = "";
	String type = "";
	String level = "";
	String frequency = "";
	String action_type = "";
	String attack_type = "";
	String range = "";
	String target = "";
	String attack = "";
	String defense = "";
	String title = "";
	String flavor_text = "";
	ArrayList<String> keywords = new ArrayList<String>();
	String hit = "";
	String miss = "";
	String effect = "";
	
	PowerCard(){}
	
	public static ArrayList<PowerCard> xml_to_pc(XmlResourceParser xml) throws XmlPullParserException, IOException{
        ArrayList<PowerCard> pcl = new ArrayList<PowerCard>();
        PowerCard pc = new PowerCard();
        String tag_type = "";
        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
         if(eventType == XmlPullParser.START_TAG) {
             System.out.println("Start tag "+xml.getName());
             if (xml.getName().equals("PowerCard")) {
            	 pc = new PowerCard();
            	 pc.classe = xml.getAttributeValue(null, "classe");
            	 pc.frequency = xml.getAttributeValue(null, "frequency");
            	 pc.action_type = xml.getAttributeValue(null, "action_type");
            	 pc.attack_type = xml.getAttributeValue(null, "attack_type");
            	 pc.range = xml.getAttributeValue(null, "range");
             } else if (xml.getName().equals("KeyWord")) {
            	 pc.keywords.add(xml.getAttributeValue(null, "name"));
             } else {
            	 tag_type = xml.getName();
             }
         } else if(eventType == XmlPullParser.END_TAG) {
             if (xml.getName().equals("PowerCard")) {
                 pcl.add(pc);
              }
         } else if(eventType == XmlPullParser.TEXT) {
        	 if (tag_type.equals("Title")) {
            	 pc.title = xml.getText();
             } else if (tag_type.equals("FlavorText")) {
            	 pc.flavor_text = xml.getText().trim();
             } else if (tag_type.equals("Hit")) {
            	 pc.hit = xml.getText().trim();
             }
         }
         eventType = xml.next();
        }
		return pcl;
	}
}
